package com.syq.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.syq.annotation.RequiresPermissionsDesc;
import com.syq.pojo.DtsAddress;
import com.syq.service.DtsAddressService;
import com.syq.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: AddressController
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/25 21:57
 */

@RestController
@RequestMapping("/admin/address")
@CrossOrigin
public class AddressController {

    @Autowired
    private DtsAddressService dtsAddressService;

    @RequiresPermissionsDesc(menu = {"用户管理","地址管理"},button = "查询")
    @RequiresPermissions(value = "admin:address:list")
    @GetMapping("/list")
    public Object list(@RequestParam(defaultValue = "1")Integer page,
                       @RequestParam(defaultValue = "10")Integer limit, String name,Integer userId,
                       @RequestParam(defaultValue = "add_time")String sort,
                       @RequestParam(defaultValue = "desc")String order){
        Map<String,Object> map=new HashMap<>();
        IPage<DtsAddress> addressIPage=dtsAddressService.findByPage(page,limit,name,userId,sort,order);
        map.put("total",addressIPage.getTotal());
        map.put("items",addressIPage.getRecords());
        return ResponseUtil.ok(map);
    }
}
